package online.mjchow.fic.config;

import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ErrorPage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

/**
 * Created by mjchow on 17-11-29.
 */
@Configuration
public class ErrorPageConfig {

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return new EmbeddedServletContainerCustomizer() {
            String prefix = "";
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container) {
//                container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, prefix +" /400"));
                container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, prefix + "/500"));
                container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, prefix + "/404"));
                container.addErrorPages(new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, prefix + "/405"));
            }
        };
    }
}
